package com.example.jeelw.common.webservice.config;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.jeelw.business.webService.service.IWebService;
import com.example.jeelw.business.webService.service.impl.WebServiceImpl;

@Configuration
public class WebServiceConfig {

	/**
	 * 注入servlet bean name不能dispatcherServlet 否则会覆盖dispatcherServlet
	 * 
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Bean(name = "cxfServlet")
	public ServletRegistrationBean cxfServlet() {
		return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
	}

	@Bean
	public IWebService webser() {
		return new WebServiceImpl();
	}

	@Bean(name = Bus.DEFAULT_BUS_ID)
	public SpringBus springBus() {
		return new SpringBus();
	}

	/**
	 * 注册WebServiceDemoService接口到webservice服务
	 * 
	 * @return
	 */
	@Bean(name = "WebServiceDemoEndpoint")
	public Endpoint sweptPayEndpoint() {
		EndpointImpl endpoint = new EndpointImpl(webser());
		endpoint.publish("/webservice");
		return endpoint;
	}

}
